﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;

public partial class Controls_Hotel_ctrHotelCatDetail : System.Web.UI.UserControl
{
    private int nCurrentlanguage = Support.GetCurrentLanguage();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Initdata();
        }
      
    }
    private void Initdata()
    {
        int nCity = ConvertData.ConvertToInt(Request.QueryString[Config.CITY]);
        int nHotel = ConvertData.ConvertToInt(Request.QueryString[Config.HOTELID]);
        if (nHotel == 0)//Hotel Cat
        {
            int nCountry = this.GetCountry();
            City objHotelCat = new City();
            DataTable dtbCat = new DataTable();
            dtbCat = objHotelCat.SearchByCountry(this.GetCountry());
            nCity = ConvertData.ConvertToInt(dtbCat.Rows[0]["CityID"]);
            lblTopDeal.Text = MultipleLanguage.TOPDEALHOTEL[nCurrentlanguage - 1];
        }
        else//Hotel Details
        {
            Hotel objHotel = new Hotel();
            objHotel.LoadById(nHotel);
            nCity = objHotel.Data.CityID;
            lblTopDeal.Text = MultipleLanguage.HOTEL_SUGGESTION[nCurrentlanguage - 1];
        }
        lnkShowall.Text = MultipleLanguage.GETMOREHOTEL[nCurrentlanguage - 1];
        lnkShowall.NavigateUrl = "~/ctrHotelList.ascx?" + Config.CITY + "=" + nCity + "&cid=" + GetCountry();

        this.TopDeal(nCity);
    }

    private int GetCountry()
    {
        int nCountry = 0;
        nCountry = ConvertData.ConvertToInt(Request.QueryString[Config.COUNTRY]);
        if (nCountry == 0)
            nCountry = Config.COUNTRY_DEFAULT;
        return nCountry;
    }

    private void TopDeal(int nCity)
    {
        Hotel objHotel = new Hotel();
        DataTable dtbHotel = new DataTable();
        int nPageCount = 0;
        dtbHotel = objHotel.Search(0, "", 0, nCity, 0, 0, 1,5,ref nPageCount);
       
        rptHotel.DataSource = dtbHotel;
        rptHotel.DataBind();
    }
 
    protected void rptHotel_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + nID + "&cid=" + this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }
  
    protected void rptHotel_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {

            HyperLink lnkHotelName = (HyperLink)e.Item.FindControl("lnkHotelName");
            ImageButton imgbtnHotel = (ImageButton)e.Item.FindControl("imgHotel");
            HyperLink lnkReadAll = (HyperLink)e.Item.FindControl("lnkReadAll");
            Label lblAddress = (Label)e.Item.FindControl("lblAddress");
            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            HyperLink lnkBooking = (HyperLink)e.Item.FindControl("lnkBooking");
            
            lnkReadAll.Text = MultipleLanguage.LNK_READMORE[nCurrentlanguage - 1];
            lnkHotelName.NavigateUrl = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID")) + "&cid=" + this.GetCountry(); 
            lnkReadAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID")) + "&cid=" + this.GetCountry();
            lnkBooking.NavigateUrl = "~/HotelBooking.aspx?hid=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID")) + "&cid=" + this.GetCountry(); 
            imgbtnHotel.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            imgbtnHotel.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID"));
            string sInitContent = "";
            switch (nCurrentlanguage)
            {
                case 1:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title1"));
                    lblAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address1"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent1"));
                    break;
                case 2:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title2"));
                    lblAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address2"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent2"));
                    break;
                case 3:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title3"));
                    lblAddress.Text = "Dirección:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address3"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent3"));
                    break;
            }
            sInitContent = ConvertData.TruncateString(sInitContent, 200) + "...";  
            lblInitContent.Text = sInitContent;

            HtmlImage lblValStarRating = (HtmlImage)e.Item.FindControl("lblValStarRating");
            Support.GetStar(lblValStarRating, ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StarRating")));
        }
    }
}